#include "../Renderer/Renderer.h"
#include "../external/external.h"

namespace Nitro::Renderer {

Window::Window(const char* title, int w, int h)
{
    glfwInit();
    Nitro::Renderer::Init();
    windowTitle = title;
    window = glfwCreateWindow(w, h, title, 0, 0);
    glfwMakeContextCurrent((GLFWwindow*)window);
    gladLoadGLLoader(GLADloadproc(glfwGetProcAddress));
    glfwSetWindowSizeCallback((GLFWwindow*)window, [](auto, int w, int h) {
        glViewport(0, 0, w, h);
    });
}

std::string Window::title() { return windowTitle; }
void Window::setTitle(const char* title)
{
    windowTitle = title;
    glfwSetWindowTitle((GLFWwindow*)window, title);
}

void Window::setSize(int w, int h)
{
    glfwSetWindowSize((GLFWwindow*)window, w, h);
}

bool Window::running() { return !glfwWindowShouldClose((GLFWwindow*)window); }
void Window::update()
{
    glfwSwapBuffers((GLFWwindow*)window);
    glfwPollEvents();
}

}; // namespace Nitro::Renderer